<template>
  <div class="hotel">
    <headers></headers>
    
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <h1>景区酒店</h1>
        <p>精选舒适住宿，让您的旅程更加完美</p>
        <div class="search-box">
          <el-select 
            v-model="search.attractions" 
            placeholder="选择景点"
            clearable
            @keyup.enter.native="searchPage"
          >
            <el-option
              v-for="(item,index) in attractions"
              :key="index"
            :label="item.name"
            :value="item.name">
            </el-option>
        </el-select>
          <el-input
            v-model="search.name"
            placeholder="酒店名称"
            prefix-icon="el-icon-house"
            clearable
            @keyup.enter.native="searchPage"
          ></el-input>
          <el-button type="primary" @click="searchPage" icon="el-icon-search">搜索</el-button>
          <el-button @click="resetSearch" icon="el-icon-refresh">清空</el-button>
        </div>
      </div>
    </div>

    <!-- 酒店列表 -->
    <div class="content-section">
      <div class="hotels-grid">
        <div class="hotel-card" v-for="(item, index) in tableData" :key="index">
          <div class="card-image" :style="{ backgroundImage: `url(${item.images.split(',')[0]})` }">
            <div class="card-overlay">
              <div class="price-tag" v-if="item.price">
                <span class="currency">¥</span>
                <span class="amount">{{item.price}}</span>
                <span class="unit">/晚</span>
              </div>
              <el-button 
                type="danger" 
                round
                class="book-button" 
                @click="toInfo(item.id)"
              >立即预订</el-button>
            </div>
          </div>
          <div class="card-content">
            <h3>{{item.name}}</h3>
            <div class="hotel-info">
              <span class="location" v-if="item.attractions">
                <i class="el-icon-location"></i>
                {{item.attractions}}
              </span>
              <span class="rating" v-if="item.rating">
                <i class="el-icon-star-on"></i>
                {{item.rating}}
              </span>
            </div>
            <p class="description">{{item.introduce}}</p>
            <div class="amenities" v-if="item.amenities">
              <span class="amenity" v-for="(amenity, i) in item.amenities.split(',')" :key="i">
                <i class="el-icon-check"></i>
                {{amenity}}
              </span>
            </div>
          </div>
        </div>
      </div>

      <!-- 分页 -->
      <div class="pagination-container">
      <el-pagination
        background
        :page-size="search.pageSize"
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :total="total">
      </el-pagination>
    </div>
    </div>

    <bottoms></bottoms>
  </div>
</template>

<script>
import { getSysHotelPage, getSysAttractionsList } from '../../api/api'
  import headers from '@/components/header'
  import bottoms from '@/components/bottom'

  export default {
  name: 'Hotel',
  components: {
    headers,
    bottoms
  },
    data() {
    return {
        search: {
          name: "",
          state: "1",
          attractions: "",
          pageSize: 12,
          pageNumber: 1,
        },
      total: 100,
        tableData: [],
        attractions: [],
      }
    },
    methods: {
      getSysAttractionsList() {
        getSysAttractionsList().then(res => {
          if (res.code == 1000) {
            this.attractions = res.data
          }
        })
      },
      searchPage() {
      this.search.pageNumber = 1
        this.getSysHotelPage()
      },
      getSysHotelPage() {
        getSysHotelPage(this.search).then(res => {
          if (res.code == 1000) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      },
      toInfo(id) {
        this.$router.push("/hotelInfo?id=" + id)
      },
      handleCurrentChange(val) {
        this.search.pageNumber = val
        this.getSysHotelPage()
      }, 
    resetSearch() {
      this.search.attractions = "";
      this.search.name = "";
      this.search.pageNumber = 1;
      this.getSysHotelPage();
    }
    },
    mounted() {
      this.getSysAttractionsList()
      this.getSysHotelPage()
    }
 }
</script>

<style scoped>
.hotel {
  min-height: 100vh;
  background-color: #f8f9fa;
}

/* 页面头部样式 */
.page-header {
  background: linear-gradient(135deg, #9C27B0 0%, #7B1FA2 100%);
  background-size: cover;
  background-position: center;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  text-align: center;
  margin-bottom: 40px;
}

.header-content {
  max-width: 800px;
  padding: 0 20px;
}

.header-content h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.header-content p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* 搜索框样式 */
.search-box {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 1rem;
  max-width: 1000px;
  margin: 0 auto;
}

.search-box .el-input,
.search-box .el-select {
  width: 100%;
}

.search-box .el-input__inner,
.search-box .el-select .el-input__inner {
  height: 50px;
  border-radius: 25px;
  padding-left: 20px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.9);
}

.search-box .el-button {
  height: 50px;
  border-radius: 25px;
  padding: 0 30px;
}

/* 内容区域样式 */
.content-section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 酒店卡片网格 */
.hotels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 30px;
  margin-bottom: 40px;
}

/* 酒店卡片样式 */
.hotel-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transition: transform 0.3s ease;
}

.hotel-card:hover {
  transform: translateY(-5px);
}

.card-image {
  height: 200px;
  background-size: cover;
  background-position: center;
  position: relative;
}

.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.2), rgba(0,0,0,0.5));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.hotel-card:hover .card-overlay {
  opacity: 1;
}

.price-tag {
  background: rgba(255, 255, 255, 0.9);
  color: #f56c6c;
  padding: 8px 12px;
  border-radius: 20px;
  align-self: flex-start;
}

.currency {
  font-size: 0.9rem;
}

.amount {
  font-size: 1.2rem;
  font-weight: bold;
  margin: 0 2px;
}

.unit {
  font-size: 0.8rem;
  color: #606266;
}

.book-button {
  align-self: center;
  margin-bottom: 20px;
}

.card-content {
  padding: 20px;
}

.card-content h3 {
  font-size: 1.25rem;
  color: #303133;
  margin-bottom: 10px;
  font-weight: 500;
}

.hotel-info {
  display: flex;
  gap: 15px;
  margin-bottom: 10px;
  color: #909399;
  font-size: 0.9rem;
}

.location, .rating {
  display: flex;
  align-items: center;
  gap: 5px;
}

.rating i {
  color: #ffd700;
}

.description {
  color: #606266;
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 15px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.amenities {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.amenity {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #67c23a;
  font-size: 0.9rem;
}

/* 分页容器样式 */
.pagination-container {
  display: flex;
  justify-content: center;
  margin: 40px 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .page-header {
    height: 400px;
  }

  .header-content h1 {
    font-size: 2rem;
  }

  .header-content p {
    font-size: 1rem;
  }

  .search-box {
    grid-template-columns: 1fr;
  }

  .hotels-grid {
    grid-template-columns: 1fr;
  }
}
</style>